package com.rd.student.jiaji.class3.zhangshixuan.Day0731;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Demo {
    public static void main(String[] args) {
        ArrayList list=new ArrayList();
        for (int i = 0; i < 50; i++) {
            list.add(i);
        }
        int len=list.size();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要随机的个数:");
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int index = (int) (Math.random() * len);
            System.out.println(list.get(index));
        }
        int[] indexArr1 = new int[len];
        for (int i = 0; i < indexArr1.length; i++) {
            indexArr1[i] = -1;
        }
        System.out.println(Arrays.toString(indexArr1));
        for (int i = 0; i < n; i++) {
            int random = (int) (Math.random() * len);
            if (indexArr1[random] == -1) {
                indexArr1[random] = random;
                System.out.println("本次随机出"+random);
                System.out.println(list.get(random));
                System.out.println(Arrays.toString(indexArr1));
            } else {
                System.out.println("已经随机过"+random);
                i--;
            }
        }

    }
}
